package com.ruoyi.web.controller.dict;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dict.domain.TDictPartType;
import com.ruoyi.dict.service.ITDictPartTypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 备件类型Controller
 * 
 * @author ruoyi
 * @date 2025-09-24
 */
@RestController
@RequestMapping("/system/part/type")
public class TDictPartTypeController extends BaseController
{
    @Autowired
    private ITDictPartTypeService tDictPartTypeService;

    /**
     * 查询备件类型列表
     */
    @PreAuthorize("@ss.hasPermi('system:partType:list')")
    @GetMapping("/list")
    public TableDataInfo list(TDictPartType tDictPartType)
    {
        startPage();
        List<TDictPartType> list = tDictPartTypeService.selectTDictPartTypeList(tDictPartType);
        return getDataTable(list);
    }

    /**
     * 导出备件类型列表
     */
    @PreAuthorize("@ss.hasPermi('system:partType:export')")
    @Log(title = "备件类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TDictPartType tDictPartType)
    {
        List<TDictPartType> list = tDictPartTypeService.selectTDictPartTypeList(tDictPartType);
        ExcelUtil<TDictPartType> util = new ExcelUtil<TDictPartType>(TDictPartType.class);
        util.exportExcel(response, list, "备件类型数据");
    }

    /**
     * 获取备件类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:partType:query')")
    @GetMapping(value = "/{code}")
    public AjaxResult getInfo(@PathVariable("code") String code)
    {
        return success(tDictPartTypeService.selectTDictPartTypeByCode(code));
    }

    /**
     * 新增备件类型
     */
    @PreAuthorize("@ss.hasPermi('system:partType:add')")
    @Log(title = "备件类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TDictPartType tDictPartType)
    {
        return toAjax(tDictPartTypeService.insertTDictPartType(tDictPartType));
    }

    /**
     * 修改备件类型
     */
    @PreAuthorize("@ss.hasPermi('system:partType:edit')")
    @Log(title = "备件类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TDictPartType tDictPartType)
    {
        return toAjax(tDictPartTypeService.updateTDictPartType(tDictPartType));
    }

    /**
     * 删除备件类型
     */
    @PreAuthorize("@ss.hasPermi('system:partType:remove')")
    @Log(title = "备件类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{codes}")
    public AjaxResult remove(@PathVariable String[] codes)
    {
        try {
            return toAjax(tDictPartTypeService.deleteTDictPartTypeByCodes(codes));
        } catch (Exception ex) {
            return AjaxResult.error(ex.getMessage());
        }
    }
}
